package org.jdemo.search.lucene;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

import java.io.File;

/**
 * MergeDemo
 *
 * @author longlin(longlin@cyou-inc.com)
 * @date 202014/3/31
 * @since V1.0
 */
public class MergeDemo {
    public static void main(String[] args) throws Exception {
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_47);
        Directory directory = FSDirectory.open(new File("F:\\temp\\luceneidx"));
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_47, analyzer);
        final IndexWriter writer = new IndexWriter(directory, config);

        long startTime = System.currentTimeMillis();
        writer.forceMerge(1);
        System.out.println("耗时: " + (System.currentTimeMillis() - startTime) + "ms");

        writer.close();
        directory.close();
    }
}
